<div id="basic-modal-content">
	<h3 class="form-title">新建日程</h3>
	<table border="0" padding="0" style="height:200px;width:300px;margin:auto;">
		<tr>
			<td class="tdLeft"><span>时间</span></td>
			<td class="tdRight"><input id="f_date1" class="Wdate" type="text" onClick="WdatePicker()"/></td>
		</tr>
		<tr>			
			<td class="tdLeft"><span>地点</span></td><td class="tdRight"><span id="location"></span></td>
		</tr>
		<tr>
			<td class="tdLeft"><span>活动</span></td>
			<td class="tdRight"><select name="want" id="want" mSty="blueCircle" onchange="a();">
			<option value='work'>工作</option>
			<option value="play">娱乐</option>
			<option value="eat">饮食</option>
			<option value="sport">运动</option>
			<option value="meet">聚会</option>
			<option value="rest">休息</option>
			<option value="other">其他</option>
		</select></td>
		</tr>		
		<tr>
			<td>
			</td>
		</tr>
	</table>
	<div id="form-btns">
		<a class="form-btn" href="javascript:create_cal();" id="sub_cal">提交</a>	
		<a class="form-btn" href="javascript:cancel_cal();">取消</a>
	</div>
	<div id="form-alert">
		<span class="form-msg"></span>
	</div>
	
</div>
<script type="text/javascript">
	//关闭弹出框
	function cancel_cal(){
		$.modal.close();
	}
	
//这个方法是用来测试选择其他
  function a(){
   var obj=document.getElementById("want");
   if(obj.options[obj.selectedIndex].value=='other'){
    window.alert(obj.options[obj.selectedIndex].value);
   }   
  }

  
  var xmlHttp;
 //响应创建cal的ajax函数
  function create_cal(){
  	var location_data=document.getElementById("location_data");
  	if(location_data == null)
  	{
  		$("#form-alert").addClass("error");
  		flashMsg("请选择地点");
	  	return;
  	}
  	if(location_data.value=="")
  	{
  		$("#form-alert").addClass("error");
  		flashMsg("请选择地点");
	  	return;
  	}
  	
  	var datas=location_data.value.split('|');
  	var location_x=datas[0];
  	var location_y=datas[1];
  	var title=datas[2];
  	var location_address=datas[3];
  	
	  var obj=document.getElementById("want");
	  var time=document.getElementById("f_date1").value;
	  
	  if(time.length!=16)
	  {
  		$("#form-alert").addClass("error");
		  flashMsg("请选择时间");
		  return;
	  }
	  
	  if(obj.value == "")
	  {
  		$("#form-alert").addClass("error");
	  	flashMsg("请选择活动");
	  	return;
	  }
	  
		//调用xmlhttp.js文件中的方法
	  xmlHttp=GetXmlHttpObject();
	  send_post_data(xmlHttp,obj.value,time,title,location_x,location_y,location_address); 
  }
  
  function send_post_data(xmlhttp,type,time,title,location_x,location_y,location_address){
	  if (xmlhttp==null)
	  {
	  	alert ("Browser does not support HTTP Request");
	  	return;
	  }
	  var url="mypage/create_calender";
	  xmlhttp.onreadystatechange=stateChanged;
	  xmlhttp.open("POST",url,true);
	  xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded;charset=utf-8");
	  xmlhttp.send("type="+type+"&time="+time+"&title="+title+"&location_x="+location_x+"&location_y="+location_y+"&location_address="+location_address); 
  }

  

  function stateChanged() 
  { 
  	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 	{   	
 			$.modal.close();
   	 		flash_success_message(xmlHttp.responseText); 
   	} 
  }
  
  function flashMsg(val){
  	$("#form-alert").show();
  	$(".form-msg").text(val);
  	setTimeout(function(){
  		$("#form-alert").fadeOut("slow");
  	},1000);
  }

 </script>